/**
 * [cookie description]
 * author yueshuai
 * set 为设置cookie get为获取cookie del为删除cookie getAll 为获取所有的cookie
 * @type {Object}
 */
const cookie = {
    set: function(key, value, h) {
        var str = key + "=" + encodeURIComponent(value); //decodeURIComponent反编码  使用escape也可编码，unescape反过来；
        if (h > 0) {
            var date = new Date();
            var ms = h * 3600 * 1000;
            date.setTime(date.getTime() + ms);
            str += "; expires=" + date.toGMTString();
        }
        document.cookie = str;
    },
    get: function(key) {
        var cookieArr = document.cookie.split("; ");
        for (var i = 0; i < cookieArr.length; i++) {
            var temp = cookieArr[i].split("=");
            if (temp[0] == key) {
                return decodeURIComponent(temp[1]);
            }
        }
    },
    del: function(key) {
        var date = new Date();
        date.setTime(-10000);
        document.cookie = key + "=a; expires=" + date.toGMTString() + ";path=/;domain=.zulong.com";
    },
    getAll: function() {
        var cookieStr = document.cookie;
        var cookieArr = document.cookie.split("; ");
        var allArr = [];
        if (cookieStr) {
            for (var i = 0; i < cookieArr.length; i++) {
                var temp = cookieArr[i].split("=");
                allArr.push(temp);
            }
            return allArr;
        }
    }
};
export default cookie;